/**
 * 
 */
package org.yelongframework.model.support.mybatis.sql.executor;

import java.util.Objects;

import org.apache.ibatis.session.SqlSession;
import org.yelongframework.lang.Nullable;
import org.yelongframework.model.support.mybatis.mapper.GenericMapperParamBuilder;
import org.yelongframework.model.support.spring.jdbc.TransactionalMybatisSqlExecutor;
import org.yelongframework.sql.executor.DataSourceProperties;

/**
 * mybatis实现的SQL执行器默认实现
 * 
 * @since 1.0.0
 */
public class DefaultMybatisSqlExecutor extends TransactionalMybatisSqlExecutor {

	@Nullable
	private final DataSourceProperties dataSourceProperties;

	private final SqlSession sqlSession;

	// ==================================================constructor==================================================

	/**
	 * @param sqlSession           sqlSession
	 * @param dataSourceProperties 数据源属性
	 */
	public DefaultMybatisSqlExecutor(SqlSession sqlSession, @Nullable DataSourceProperties dataSourceProperties,
			GenericMapperParamBuilder genericMapperParamBuilder) {
		super(genericMapperParamBuilder);
		this.sqlSession = Objects.requireNonNull(sqlSession, "sqlSession cannot be null");
		this.dataSourceProperties = dataSourceProperties;
	}

	// ==================================================数据源配置==================================================

	@Override
	public DataSourceProperties getDataSourceProperties() {
		return dataSourceProperties;
	}

	// ==================================================SQL会话==================================================

	@Override
	public SqlSession getSqlSession() {
		return this.sqlSession;
	}

}
